import React from 'react';
import {Menu, Icon } from 'antd';
import { Link } from 'dva/router';
import { connect } from 'dva';
import './LeftNav.css';
const { SubMenu } = Menu;
const {MenuItemGroup} = Menu.ItemGroup;

const LeftNav = React.createClass ({
	getInitialState() {
	    return {
	      	current: '1',
	    };
	},
	handleClick(e) {
	    this.setState({
	      	current: e.key,
	    });
	},
	render(){
		let isHidden=this.props.common.iscollapsed;
		return (
			<Menu onClick={this.handleClick}
			defaultOpenKeys={['sub1']}
			selectedKeys={[this.state.current]}
			mode={isHidden?'vertical': 'inline'}
			theme="light"
			>
				{
					this.props.leftNavData.map((v,i)=>{
						let nav=v.tabList?
							(<SubMenu key={"sub"+i} title={<span><Icon type={v.SubMenuTabIcon} /><span className="nav-text">{v.SubMenuTabName}</span></span>}>
					          	
			        			{v.tabList.map((value,index)=>{
			        				var childNav=(<Menu.Item key={"child"+i+index}>
									        		{
									        			value.tabLink?
									        				(<Link to={value.tabLink}><Icon type={value.tabIcon} />{value.tabName}</Link>)
															:<span><Icon type={value.tabIcon} />{value.tabName}</span>
									        		}
									        	</Menu.Item>);
									return childNav;
			        			})}
				        		
					        </SubMenu>)
							:
							(<Menu.Item key={i}>
				        		{
				        			v.tabLink?
				        				(<Link to={v.tabLink}><Icon type={v.tabIcon} /><span className="nav-text">{v.tabName}</span></Link>)
				        				:<span><Icon type={v.tabIcon} /><span className="nav-text">v.tabName</span></span>
				        		}
				        	</Menu.Item>);
				        	
				        return nav
						
					})
				}
			</Menu>	
		)
	}
})


function mapStateToProps({ common}) {
    return {common};
}
export default connect(mapStateToProps)(LeftNav) ;
